package com.soft.servlet;

import com.soft.entity.UserInfo;
import com.soft.service.Domain;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "MemberManageListServlet",urlPatterns = "/MemberManageList")
public class MemberManageListServlet extends HttpServlet {

    private Domain domain;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        domain = new Domain();

        List<UserInfo> list = new ArrayList<UserInfo>();
        list = domain.getUserAll();
        request.setAttribute("UserList", list);
        request.getRequestDispatcher("/memberManageList.jsp").forward(request, response);

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        domain = new Domain();

        String id = request.getParameter("account");
        UserInfo ui = domain.getUserInfo(id);

        if (domain.LockOrFreeUser(id)){
            if (ui.getStatus() == UserInfo.STATUS.STATUS_NORMAL)
                request.getSession().setAttribute("flag", 33);
            else
                request.getSession().setAttribute("flag", 34);
        } else {
            if (ui.getStatus() == UserInfo.STATUS.STATUS_NORMAL)
                request.getSession().setAttribute("flag", 35);
            else
                request.getSession().setAttribute("flag", 36);
        }
        doGet(request, response);
    }
}
